package com.gw.rabbitmq.mq.send;

import com.gw.rabbitmq.RabbitKit;
import com.jfinal.kit.PropKit;
import com.rabbitmq.client.Channel;
import com.rabbitmq.client.Connection;
import com.rabbitmq.client.ConnectionFactory;

/**
 * 测试发送
 */
public class Send {

    private static String queue = PropKit.get("RabbitMQ.queue","test");
//    public static void main(String[] argv) throws Exception {
//        RabbitKit.getInstance().sendSimpleMessage(queue);
//    }

    private final static String QUEUE_NAME = "hello";

    public static void main(String[] argv) throws Exception {
        ConnectionFactory factory = RabbitKit.getInstance().getFactory();

        try (Connection connection = factory.newConnection();
             Channel channel = connection.createChannel()) {
            channel.queueDeclare(QUEUE_NAME, false, false, false, null);
            String message = "哈哈 你是谁!";
            channel.basicPublish("", QUEUE_NAME, null, message.getBytes("UTF-8"));
            System.out.println(" [x] Sent '" + message + "'");
        }
    }
}
